/**
 * Copyright (c) 2009 Teoti Graphix, LLC See:
 *     http://tkarchitecture.teotigraphix.org
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * @author Michael Schmalle mschmalle@teotigraphix.com
 */
package org.example.ui.component.button
{

import org.example.ui.behavior.ButtonBehaviorCore;
import org.example.ui.behavior.ButtonIconBehavior;
import org.example.ui.behavior.ButtonLabelBehavior;
import org.example.ui.behavior.IIconBehavior;
import org.example.ui.behavior.ILabelBehavior;
import org.example.ui.model.ButtonModelCore;
import org.example.ui.skin.IconButtonSkin;
import org.teotigraphix.dx.interfaces.IBehaviorLayerAware;
import org.teotigraphix.dx.interfaces.IComponentBehaviorCore;
import org.teotigraphix.dx.interfaces.IComponentModelCore;
import org.teotigraphix.dx.interfaces.IComponentSkinCore;
import org.teotigraphix.dx.interfaces.IToolKitComponent;
import org.teotigraphix.dx.patterns.component.ToolKitFactory;

/**
 * The default toolkit implementation for the <code>Button</code> component.
 * 
 * @copyright Teoti Graphix, LLC
 * @author Michael Schmalle
 * @date 07-14-09
 */
public class ButtonToolKitFactory 
	   extends ToolKitFactory
	   implements IButtonToolKitFactory
{
	//--------------------------------------------------------------------------
	//
	//  Public Properties :: Methods
	//
	//--------------------------------------------------------------------------
	
	//----------------------------------
	//  labelBehavior
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _labelBehavior:ILabelBehavior;

	/**
	 * Returns the mxml implementation of the <code>labelBehavior</code>.
	 */
	public function get labelBehavior():ILabelBehavior
	{
		return _labelBehavior;
	}
	
	/**
	 * @private
	 */
	public function set labelBehavior(value:ILabelBehavior):void
	{
		_labelBehavior = value;
	}	
	
	//----------------------------------
	//  iconBehavior
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _iconBehavior:IIconBehavior;

	/**
	 * Returns the mxml implementation of the <code>iconBehavior</code>.
	 */
	public function get iconBehavior():IIconBehavior
	{
		return _iconBehavior;
	}
	
	/**
	 * @private
	 */
	public function set iconBehavior(value:IIconBehavior):void
	{
		_iconBehavior = value;
	}
	
	//--------------------------------------------------------------------------
	//
	//  Overridden Public :: Methods
	//
	//--------------------------------------------------------------------------
	
	// NOTE :: This is not implemeted because we are using an Adobe skin 
	// that does not implement IComponentSkinCore, thus we add the skin
	// through the normal skinClass style and not the toolkit factory
	
	/**
	 * @inheritDoc
	 * @uses org.example.skins.IconButtonSkin
	 */
//	override public function createCoreSkin():IComponentSkinCore
//	{
//		return (coreSkin) ? coreSkin : new IconButtonSkin();
//	}
	
	/**
	 * @inheritDoc
	 * @uses org.example.behaviors.ButtonCoreService
	 */
	override public function createCoreModel():IComponentModelCore
	{
		return (coreModel) ? coreModel : new ButtonModelCore();
	}
	
	/**
	 * @inheritDoc
	 * @uses org.example.behaviors.ButtonCoreBehavior
	 */
	override public function createCoreBehavior():IComponentBehaviorCore
	{
		return (coreBehavior) ? coreBehavior : new ButtonBehaviorCore();
	}
	
	/**
	 * @inheritDoc
	 * @uses #createLabelBehavior()
	 * @uses #createIconBehavior()
	 */
	override public function createComponents(client:IToolKitComponent):void
	{
		super.createComponents(client);
		
		var baware:IBehaviorLayerAware = IBehaviorLayerAware(client);
		
		if (!baware.behaviorLayer.hasBehavior(ILabelBehavior))
		{
			baware.behaviorLayer.registerBehavior(
				ILabelBehavior, createLabelBehavior());
		}
		
		if (!baware.behaviorLayer.hasBehavior(IIconBehavior))
		{
			baware.behaviorLayer.registerBehavior(
				IIconBehavior, createIconBehavior());
		}
	}
	
	//--------------------------------------------------------------------------
	//
	//  Methods
	//
	//--------------------------------------------------------------------------
	
	/**
	 * @copy IButtonToolKitFactory#createLabelBehavior()
	 * @uses org.example.behaviors.ButtonLabelBehavior
	 */
	public function createLabelBehavior():ILabelBehavior
	{
		return (_labelBehavior) ? _labelBehavior : new ButtonLabelBehavior();
	}
	
	/**
	 * @copy IButtonToolKitFactory#createIconBehavior()
	 * @uses org.example.behaviors.ButtonIconBehavior
	 */
	public function createIconBehavior():IIconBehavior
	{
		return (_iconBehavior) ? _iconBehavior : new ButtonIconBehavior();
	}
	
	//--------------------------------------------------------------------------
	//
	//  Public Class :: Methods
	//
	//--------------------------------------------------------------------------
	
	/**
	 * @private
	 */
	private static var instance:ButtonToolKitFactory;
	
	/**
	 * Returns the single instance of the factory.
	 * @uses org.example.components.supportClasses.ButtonToolKitFactory
	 */	
	public static function getInstance():ButtonToolKitFactory
	{
		if (!instance)
			instance = new ButtonToolKitFactory();
		return instance;
	}
}
}